#-*- Makefile -*-
#
# ${R_HOME}/src/library/tools/Makefile

srcdir = .
top_srcdir = ../../..

top_builddir = ../../..

pkg = tools

RSRC = `LC_COLLATE=C ls $(srcdir)/R/*.R`

R_EXE = $(top_builddir)/bin/Rterm.exe --vanilla --slave

ECHO = echo
MKINSTALLDIRS = mkdir -p
INSTALL_DATA = cp
SHELL = sh
USE_NLS =yes

all:
	@$(ECHO) "building package '$(pkg)'"
	@$(MKINSTALLDIRS) $(top_builddir)/library/$(pkg)
	@$(MAKE) -f Makefile.win mkR mkdesc2 mkpo
	@if test -d src; then \
	  cp -p ../../gnuwin32/dllversion.rc src/tools_res.rc; \
	  $(MAKE) -C src -f $(RHOME)/src/gnuwin32/MakeDll RHOME=$(RHOME) DLLNAME=$(pkg) || exit 1; \
	  mkdir -p $(top_builddir)/library/$(pkg)/libs; \
	  cp src/$(pkg).dll $(top_builddir)/library/$(pkg)/libs; \
	fi
	@$(INSTALL_DATA) all.R $(top_builddir)/library/$(pkg)/R/$(pkg)
	@(cat $(srcdir)/R/makeLazyLoad.R; \
	  $(ECHO) "makeLazyLoading(\"$(pkg)\")") | \
	  R_DEFAULT_PACKAGES=NULL LC_ALL=C $(R_EXE) > /dev/null
	@$(ECHO) "tools:::.install_package_description('.', '"$(top_builddir)/library/${pkg}"')" | \
	  R_DEFAULT_PACKAGES=NULL $(R_EXE) > /dev/null


include $(top_srcdir)/share/make/basepkg.mk
